package demo3;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-04
 * Time: 20:44
 */
public class Test {
    public static boolean isVaildChar(char ch){
        if(Character.isDigit(ch) || Character.isLetter(ch)){
            return true;
        }
        return false;
    }
    public static boolean isPalindrome(String s){
        s = s.toLowerCase();
        int left = 0;
        int right = s.length() - 1;
        while (left < right){
            while (left < right && !isVaildChar(s.charAt(left))){
                left++;
            }
            while (left < right && !isVaildChar(s.charAt(right))){
                right--;
            }
            if(s.charAt(left) != s.charAt(right)){
                return false;
            }else{
                left++;
                right--;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        String str = "abcdcba";
        boolean ret = isPalindrome(str);
        System.out.println(ret);
    }
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextLine()){
            String str = scanner.nextLine();
            int index = str.lastIndexOf(' ');
            String tmp = str.substring(index+1);
            System.out.println(tmp);
        }
    }
    public static int firstUniqChar(String s){
        int[] count = new int[26];
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            count[ch - 'a']++;
        }
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if(count[ch-'a'] == 1){
                return i;
            }
        }
        return -1;
    }
    public static void main1(String[] args) {
        String str = "abaabd";
        int ret = firstUniqChar(str);
        System.out.println(ret);
    }
}
